{include file="header/index" /}
<meta charset="UTF-8">
	<style>
		.form-control {
			height: 33px;
		}
	</style>

	<body>
		<div class="container wrapper-content animated fadeInRight">
			<div class="row" style="padding: 0 -20px;">
				<div class="col-sm-12" style="padding: 0;">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<h5>添加管理员</h5>
						</div>
						<div class="ibox-content">
							<form class="form-horizontal" name="userAdd" id="userAdd" method="post" action="{:url('Users/addUser')}" enctype="multipart/form-data">
								<div class="form-group">
									<label class="col-sm-3 control-label">管理员帐号：</label>
									<div class="input-group col-sm-4">
										<input id="account" type="text" class="form-control" name="account" placeholder="输入管理员帐号">
									</div>
								</div>
								<div class="hr-line-dashed"></div>
								<div class="form-group">
									<label class="col-sm-3 control-label">管理员用户组：</label>
									<div class="input-group col-sm-4">
										<select class="form-control m-b chosen-select" name="groupid" id="groupid" >
											<option value="">==请选择用户组==</option>
											{foreach $data as $v}
												<option value="{$v.id}">{$v.title}</option>
											{/foreach}
										</select>
									</div>
								</div>
								<div class="hr-line-dashed"></div>
								<div class="form-group">
									<label class="col-sm-3 control-label">头像：</label>
									<div class="input-group col-sm-4">
										<div id="fileList" class="uploader-list" style="float:right"></div>
										<div id="imgPicker" style="float:left" class="webuploader-container">
											<div class="webuploader-pick">选择头像</div>
											<input type="file" name="avatar_img" id="avatar_img" class="webuploader-element-invisible" multiple="multiple" onchange="qwe()" accept="image/jpg,image/jpeg,image/png">
											
										</div>
										<img id="img_data" class="img-circle" height="80px" width="80px" style="float:left;margin-left: 50px;margin-top: -10px;" src="__IMG__/head_default.gif">
									</div>
								</div>
								<div class="hr-line-dashed"></div>
								<div class="form-group">
									<label class="col-sm-3 control-label">登录密码：</label>
									<div class="input-group col-sm-4">
										<input id="password" type="text" class="form-control" name="password" placeholder="输入登录密码">
									</div>
								</div>
								<div class="hr-line-dashed"></div>
								<div class="form-group">
									<label class="col-sm-3 control-label">真实姓名：</label>
									<div class="input-group col-sm-4">
										<input id="name" type="text" class="form-control" name="name" placeholder="输入管理员真实姓名">

									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">手机号：</label>
									<div class="input-group col-sm-4">
										<input id="phone" type="text" class="form-control" name="phone" placeholder="输入管理员手机号">

									</div>
								</div>
								
								
								<div class="form-group">
									<label class="col-sm-3 control-label">邮箱：</label>
									<div class="input-group col-sm-4">
										<input id="email" type="text" class="form-control" name="email" placeholder="输入管理员邮箱">

									</div>
								</div>
								
								
								<div class="form-group">
									<label class="col-sm-3 control-label">联系地址：</label>
									<div class="input-group col-sm-4">
										<input id="address" type="text" class="form-control" name="address" placeholder="输入管理员联系地址">

									</div>
								</div>
								
								
								<div class="hr-line-dashed"></div>
								<div class="form-group">
									<label class="col-sm-3 control-label">状&nbsp;态：</label>
									<div class="col-sm-6">
										<div class="switchery-radio" style="padding-top: 8px;">
											<input type="checkbox" name="status" value="1" class="js-switch" checked>
											默认开启
										</div>
									</div>
								</div>
								
								
								
								
								
								
								
								<div class="hr-line-dashed"></div>
								<div class="form-group">
									<div class="col-sm-4 col-sm-offset-3">
										<button class="btn btn-primary" type="button" onclick="addUser();"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
										<a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
									</div>
								</div>
							</form>
						</div>
					</div>

				</div>
			</div>
		</div>
		
		<script>
			
		</script>
	</body>

<script type="text/javascript">
	/**
	 * ajax 表单提交
	 */
	function addUser(){
		if($.trim($("input[name='account']").val())==''){
			layer.msg('请填写管理员帐号', {icon: 2,time: 2000});
			return false;
		}
		
		if($.trim($("input[name='password']").val())==''){
			layer.msg('请填写登录密码', {icon: 2,time: 2000});
			return false;
		}
		
		if($.trim($("input[name='name']").val())==''){
			layer.msg('请填写管理员真实姓名', {icon: 2,time: 2000});
			return false;
		}
		
		if($.trim($("input[name='phone']").val())==''){
			layer.msg('请填写管理员手机号', {icon: 2,time: 2000});
			return false;
		}
		
		if($.trim($("input[name='email']").val())==''){
			layer.msg('请填写管理员邮箱', {icon: 2,time: 2000});
			return false;
		}
		
		
		if($.trim($("input[name='email']").val())==''){
			layer.msg('请填写管理员邮箱', {icon: 2,time: 2000});
			return false;
		}
		
		
		if($.trim($("#groupid").find('option:selected').val())==''){
			layer.msg('请选择用户组', {icon: 2,time: 2000});
			return false;
		}
		
		
		if (!$("#email").val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) { 
			layer.msg('邮箱格式不正确', {icon: 2,time: 2000});
			return false;
		} 
		
		 if(!(/^1[34578]\d{9}$/.test($.trim($("input[name='phone']").val())))){ 
			layer.msg('手机号码格式不正确', {icon: 2,time: 2000});
			return false; 
	    } 
		
		 if($.trim($("input[name='address']").val())==''){
			layer.msg('请填写管理员地址', {icon: 2,time: 2000});
			return false;
		}
		
		
		var formData = new FormData($( "#userAdd" )[0]); 
	     $.ajax({    
	          url:  "{:url('Users/addUser')}",  /*这是处理文件上传的servlet*/  
	          type: 'POST',    
	          data: formData,    
	          async: false,    
	          cache: false,    
	          contentType: false,    
	          processData: false,
	          dataType : 'json',
	          success: function (returndata) {
	        	 if(returndata.code == '1'){
	        		 layer.msg(returndata.msg, {icon: 1,time: 2000},function(){window.location.href=returndata.data});
	        	 }else{
	        		 layer.msg(returndata.msg, {icon: 2,time: 2000}); 
	        	 }
	              
	          },error: function (returndata) {    
				layer.msg('数据异常', {icon: 2,time: 2000});
				return false; 
	          }    
	     });  
		
		
		
	}

	
	
	/**
	 * 图片显示
	 */

	function qwe() {
		var file = document.getElementById("avatar_img").files[0];
		var reader = new FileReader();
		reader.onload = function(e) {
			img_data.src = this.result;
		};
		reader.readAsDataURL(file); //Base64
	  }
	
	
	
</script>
</html>